package 动态规划;

// 力扣 152 非常好的一道动归
public class Solution3 {
    public int maxProduct(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        int maxPro = nums[0];
        int minPro = nums[0];
        int res = nums[0];
        for(int i = 1;i<nums.length;i++){
            int cur = nums[i];
            int lastMax = maxPro;
            maxPro = Math.max(cur,Math.max(lastMax*cur,minPro*cur));
            minPro = Math.min(cur,Math.min(lastMax*cur,minPro*cur));
            if(maxPro>res) res=maxPro;
        }
        return res;
    }
}